import i18n from '@/locales/index' 
const { t } = i18n.global

export const normalColumns =  [
  {
    title: t('common.sequenceNo'), dataIndex: 'index', key: 'index', align: 'center', width: 90,
    customRender: ({ index }) => {
      return index + 1
    }
  },
  { title: t('basicData.jobNo'), dataIndex: 'staffNo', key: 'staffNo', align: 'center' },
  { title: t('basicData.name'), dataIndex: 'nickName', key: 'nickName', align: 'center' },
  { title: t('basicData.cardNo'), dataIndex: 'cardNo', key: 'cardNo', align: 'center' },
  { title: t('basicData.group'), dataIndex: 'groupName', key: 'groupName', align: 'center' },
  { title: t('basicData.workType'), dataIndex: 'professionNameList', key: 'professionNameList', align: 'center', customRender: ({ text }) => {
    return text&& text.join(',')
  }},
  { title: t('basicData.machineType'), dataIndex: 'modelList', key: 'modelList', align: 'center' , customRender: ({ text }) => {
    return text&& text.join(',')
  }},
  { title: t('basicData.skillLv'), dataIndex: 'skillGrade', key: 'skillGrade', align: 'center' },
  { title: t('common.operate'), dataIndex: 'operate', key: 'operate', align: 'center', width: 170, fixed: 'right' }
]
export const localColumns =  [
  {
    title: t('common.sequenceNo'), dataIndex: 'index', key: 'index', align: 'center', width: 90,
    customRender: ({ index }) => {
      return index + 1
    }
  },
  { title: t('basicData.jobNo'), dataIndex: 'staffNo', key: 'staffNo', align: 'center' },
  { title: t('basicData.name'), dataIndex: 'nickName', key: 'nickName', align: 'center' },
  { title: t('basicData.cardNo'), dataIndex: 'cardNo', key: 'cardNo', align: 'center' },
  { title: t('basicData.group'), dataIndex: 'groupName', key: 'groupName', align: 'center' },
  { title: t('basicData.workType'), dataIndex: 'professionNameList', key: 'professionNameList', align: 'center', customRender: ({ text }) => {
    return text&& text.join(',')
  }},
  { title: t('basicData.machineType'), dataIndex: 'modelList', key: 'modelList', align: 'center' , customRender: ({ text }) => {
    return text&& text.join(',')
  }},
  { title: t('basicData.skillLv'), dataIndex: 'skillGrade', key: 'skillGrade', align: 'center' }
]
export const originTreeList = [
  { name: t('common.all'), id: 'all',isParent: true, children: [
    { name: t('sysManage.onGroup'), id: 'notGrouped', flag: true }
  ] }
]
const validtWorkNo = async (_rule, value) => {
  if (!value) {
    return Promise.reject(t('sysManage.enterJobNo'))
  }
  if (/^[0-9]{1,8}$/.test(value)) {
    return Promise.resolve()
  } else {
    return Promise.reject(t('sysManage.jobNoMax8'))
  }
}
const validtCard = async (_rule, value) => {
  if (!value) {
    return Promise.resolve()
  }
  if (/^[0-9]{10}$/.test(value)) {
    return Promise.resolve()
  } else {
    return Promise.reject(t('sysManage.cardNo10'))
  }
}
export const modalRules = {
  staffNo: [{
    required: true,
    trigger: 'change',
    validator: validtWorkNo
  }],
  nickName: [
    { required: true, message: t('sysManage.enterName') },
    { whitespace: true, message: t('sysManage.enterName') },
    {  max: 20, message: t('sysManage.max20') }
  ],
  cardNo: [
    {trigger: 'change', validator: validtCard}
  ]
}
export const goodProcColumns = [
  {
    title: t('common.sequenceNo'), dataIndex: 'index', key: 'index', align: 'center', width: 80,
    customRender: ({ index }) => {
      return index + 1
    }
  },
  { title: t('sysManage.goodProcNa'), dataIndex: 'adeptProcess', key: 'adeptProcess', align: 'center' },
  { title: t('common.operate'), dataIndex: 'operate', key: 'operate', align: 'center', width: 100 }
]